package com.ProdigiousAT;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.safari.SafariOptions;

import java.lang.reflect.Field;

/**
 * Created by orlandocampos on 11/14/14.
 */
public class ExampleTwo {

    private static WebDriver driver;
    private String baseUrl;

    @Before
    public void setUp() throws Exception{
        System.out.println("Hello this is @before every @Test");
        driver = new FirefoxDriver();
        baseUrl = "http://www.youtube.com/";
    }

    @Test
    public void test1() throws Exception{
        String iSearchTerm, oSearchResults, eSearchResults, iHomePageText, oHomePageText;

        int iWait;

        String[] ArraySearchTerms = {"","Automation","Training","Videos"};


        iWait = 2000;
        iSearchTerm = "Selenium ";
        iHomePageText = "Sign in now to see your channels and recommendations!";
        eSearchResults = "About 154,000 results";

        for(int i=0; i<4; i++) {
            driver.get(baseUrl);
            Thread.sleep(iWait);

            oHomePageText = driver.findElement(By.xpath("//*[@id='guide-container']/div/ul/li[4]/p")).getText();

            if(oHomePageText.equals(iHomePageText))
                System.out.print("Yay! you are on HomePage! \n");
            else
                System.out.print("=( You are not on Homepage\n");

            driver.findElement(By.xpath("//input[@id='masthead-search-term']")).sendKeys(iSearchTerm + ArraySearchTerms[i]);

            driver.findElement(By.xpath("//button[@id='search-btn']")).click();
            Thread.sleep(iWait);

            oSearchResults = driver.findElement(By.cssSelector(".num-results.first-focus")).getText();
            System.out.println("Your search result is: " + oSearchResults+"\n");

            if(oSearchResults.equals(eSearchResults))
                System.out.print("Test Passed! there are About 154,000 results\n");
            else
                System.out.print("Test Failed, there are not About 154,000 results\n");

        }

    }

    @AfterClass
    public static void tearDown(){
        driver.close();

        driver.quit();

    }
}
